# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import gvn.cmdline
import gvn.util


helptext__gvn_rdiff = """\
rdiff: Display the differences between two revisions or repository paths.
usage: 1. rdiff [-c M | -r N[:M]] [URL[@REV]...]
       2. rdiff [-r N[:M]] --old=OLD-URL[@OLDREV] [--new=NEW-URL[@NEWREV]] \
                [PATH...]
       3. rdiff OLD-URL[@OLDREV] NEW-URL[@NEWREV]

  1. Display the changes made to URLs as they are seen in REV between two
     revisions.  N must be specified and M defaults to HEAD.  The '-c M' option
     is equivalent to '-r N:M' where N = M-1.  Using '-c -M' does the reverse:
     '-r M:N' where N = M-1.

  2. Display the differences between OLD-URL as it was seen in OLDREV and
     NEW-URL as it was seen in NEWREV.  PATHs, if given, are relative to OLD-URL
     and NEW-URL and restrict the output to differences for those paths.
     OLD-URL and NEW-URL must be URL[@REV].  NEW-URL defaults to OLD-URL if not
     specified.  -r N makes OLDREV default to N, -r N:M makes OLDREV default to
     N and NEWREV default to M.

  3. Shorthand for 'gvn rdiff --old=OLD-URL[@OLDREV] --new=NEW-URL[@NEWREV]'
"""


def Handle_GvnRdiff(ctx):
  ctx.wc_operands = False
  if len(ctx.operands) == 0:
    raise gvn.errors.BadOperands(
      "Not enough arguments provided; try 'gvn rdiff -h' for more info")
  return gvn.cmdline.RunSvnCommand(ctx, 'diff', ctx.operands)

options = gvn.cmdline.AuthOptions(
  ['project', 'revision', 'change', 'old', 'new', 'non-recursive',
   'diff-cmd', 'extensions', 'no-diff-deleted', 'notice-ancestry',
   'summarize', 'force'])
gvn.cmdline.AddCommand('rdiff', Handle_GvnRdiff, helptext__gvn_rdiff, options)
